#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

double timercalc(time_t);
int sumcalc(int);

void main(int args,char* argv[]){
	time_t mytime = time(0);
	FILE *f;
    FILE *f1;

	//initialising seed
#if _WIN32||WIN32
	 int seed=atoi(argv[2]);
#endif

#if _linux||linux
	 int seed;
	 sscanf(argv[2],"%d",&seed);
#endif
	 long int sum=0;
	  int i=0;
	  int count=0;
	  int n=100;
      int time;
      char name[100]="./task";
	  char fname[100]="./Coutput.txt";
	  char endname[]=".txt";
	  int length;
	  char str[20];
	  f1=fopen(fname,"a");
	  srand( seed );
#if _WIN32||WIN32
	  time=atoi(argv[3]);
#endif
#if _linux||linux
	  sscanf(argv[3],"%d",&time);
#endif
	   for(i=0;timercalc(mytime)<time;i++){
		 sum=sum+(sumcalc(n)/100000);
		 count=count+n;
	  }
	  strcat(name,argv[1]);
      strcat(name,endname);
	  f= fopen(name, "a");
	  fprintf (f,"count=" ); 
#if _WIN32||WIN32
	  fprintf (f,itoa(count,str,10)); 
#endif
#if _linux||linux
	  sprintf(str,"%d",count);
      fprintf (f,str); 
#endif
	  fprintf (f,"  " ); 
      fprintf (f,"sum=" ); 
#if _WIN32||WIN32
	  fprintf (f,itoa(sum,str,10)); 
#endif
#if _linux||linux
	  sprintf(str,"%ld",sum);
      fprintf (f,str); 
#endif
	  fclose(f);
	 
	  fprintf(f1,"seed is %d and trails = %d",seed,count);
	  fprintf(f1,"seed is %d and time taken = %lf",seed,timercalc(mytime));
      fclose(f1);
	  printf("program is executed");
}
double timercalc(time_t t1){
	time_t t2=time(0);
	return (difftime(t2,t1));
}
int sumcalc(int n){
	int i=0;
	int num=0;
	int sum=0;
	for (i=0;i<n;i++) {
           num=rand();
		   if(num>15383)
			   num=1;
		   else 
			   num=0;
		   sum=sum+num;
    }
    return sum;
}
